//
//  GGHttpRequest.m
//  DDLock
//
//  Created by ios on 2017/12/26.
//  Copyright © 2017年 saiyi. All rights reserved.
//

#import "GGHttpRequest.h"

#import <AFNetworking/AFNetworking.h>

@interface GGHttpRequest ()

@property (nonatomic, strong) AFHTTPSessionManager *manager;

@end


@implementation GGHttpRequest

static GGHttpRequest *_instance = nil;
+ (instancetype)shareRequest {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[GGHttpRequest alloc] init];
    });
    return _instance;
}


+ (void)request {
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:@""]];
    
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager GET:@"" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
    
}

+ (void)httpRequestType:(kRequestType)type path:(NSString *)path progressHUD:(BOOL)hud parameters:(id)pam success:(void(^)(id request))resObject failure:(void(^)(NSError *err))resError {
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:@""]];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    
    
    
    switch (type) {
        case kRequestType_GET:
        {
            [manager GET:path parameters:pam progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                if (resObject) {
                    resObject(responseObject);
                }
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                if (resError) {
                    resError(error);
                }
            }];
        }
            break;
        case kRequestType_POST:
        {
            [manager POST:path parameters:pam progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                if (resObject) {
                    resObject(responseObject);
                }
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                if (resError) {
                    resError(error);
                }
            }];
        }
            break;
        default:
            break;
    }
    
    
    
    
    
}



@end
